package top.yogiczy.mytv.core.data.network

import okhttp3.OkHttpClient
import java.util.concurrent.TimeUnit

// OkHttpClientManager.kt
object OkHttpClientManager {
    private var client: OkHttpClient? = null

    fun initialize(): OkHttpClient {
        if (client == null) {
            client = OkHttpClient.Builder()
                // 可以在这里添加通用配置
                 .connectTimeout(30, TimeUnit.SECONDS)
                 .readTimeout(30, TimeUnit.SECONDS)
                // .addInterceptor(loggingInterceptor)
                .build()
        }
        return client!!
    }

    fun get(): OkHttpClient {
        return client ?: throw IllegalStateException("OkHttpClient not initialized")
    }

    fun destroy() {
        client?.dispatcher?.executorService?.shutdown()
        client?.connectionPool?.evictAll()
        client = null
    }
}